package com.demo.util;

import java.util.regex.Pattern;

public class Validator {
    // 验证用户名
    public static final String REGEX_USERNAME = "^[a-zA-Z]\\w{5,17}$";
    // 验证密码
    public static final String REGEX_PASSWORD = "^[a-zA-Z0-9]{6,16}$";
    // 验证手机号
    public static final String REGEX_MOBILE = "^((13[0-9])|(15[^4,\\D])|(14[57])|(17[0])|(17[7])|(18[0,0-9]))\\d{8}$";
    // 验证邮箱
    private static final String REGEX_EMAIL = "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}";
    // 验证抄送地址
    public static final String REGEX_CC_ADDR = "(" + REGEX_EMAIL + ")(," + REGEX_EMAIL + ")*";
    // 验证非空
    public static final String REGEX_NOT_NULL = "\\S+";

    // 校验方法
    public static boolean isUsername(String username) {
        return Pattern.matches(REGEX_USERNAME, username);
    }

    public static boolean isPassword(String password) {
        return Pattern.matches(REGEX_PASSWORD, password);
    }

    public static boolean isMobile(String mobile) {
        return Pattern.matches(REGEX_MOBILE, mobile);
    }

    public static boolean isEmail(String email) {
        return Pattern.matches(REGEX_EMAIL, email);
    }

    public static boolean CheckccAddr(String ccAddr) {
        return Pattern.matches(REGEX_CC_ADDR, ccAddr);
    }

    public static boolean isNotNull(String string) {
        return Pattern.matches(REGEX_NOT_NULL, string);
    }
}